package com.itheima.gateway.filters;

import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import reactor.core.publisher.Mono;

@Configuration
public class FiltersConfiguration {
    @Bean
    @Order(-3)
    public GlobalFilter filter1(){
        return (exchange, chain) -> {
            System.out.println("1前执行了");
            return   chain.filter(exchange).then(
                    Mono.fromRunnable(()->{
                        System.out.println("1后执行了");
                    })
            );
        };
    }
    @Bean
    @Order(-2)
    public GlobalFilter filter2(){
        return (exchange, chain) -> {
            System.out.println("二前执行了");
            return chain.filter(exchange).then(
                    Mono.fromRunnable(()->{
                        System.out.println("二后执行了");
                    })
            );
        };
    }
    @Bean
    @Order(-1)
    public GlobalFilter filter3(){
        return (exchange, chain) -> {
            System.out.println("三前执行了");
            return chain.filter(exchange).then(
                    Mono.fromRunnable(()->{
                        System.out.println("三后执行了");
                    })
            );
        };
    }
}
